<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>四川省工程建设领域项目信息、信用信息公开维护平台</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/reset.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/main.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/My97DatePicker4/WdatePicker.js"></script>
<script src="<%=request.getContextPath()%>/scripts/jquery-latest.pack.js"></script>
<script src="<%=request.getContextPath()%>/scripts/jquery.form.js"></script>
<script type="text/javascript">
var checkFlag = false;
var needAccCheck = true; //是否需要AJAX确认帐号是否重复
var account;
var userName;
var userPwd;
var orgName;
var depId;
var contacter;
var phone;
var email;
var f = null;

function checkAccount(obj)
{
	if (obj.value != "")
	{
		setTimeout(function(){checkAccountDB(obj);}, 2000);
	}
}
function checkAccountDB(obj)
{
	var options={type:"POST", 
				url:"<%=request.getContextPath()%>/user/accountAuth?account="+obj.value, 
				dataType:"json", success: resultResponse};
	$.ajax(options);
}
function resultResponse(data,status) {
	if(!needAccCheck){
		return;
	}
	var obj = document.getElementById("acr");
	if(status){
		if (data.result == 0){
			obj.innerHTML='<font color="#669933">本帐号可以使用</font>';
			checkFlag = true;
		}
		else{
			obj.innerHTML='<font color="#FF9966">账号已注册，只能修改帐号信息</font>';
			checkFlag = false;
		}
	}
	else{
		obj.innerHTML='<font color="#FFFF00">无法检测帐号</font>';
	}
}

function getAccByDep(obj)
{
	
	var ops = document.getElementsByTagName('option');
	document.getElementById("depId").value = ops[obj.selectedIndex].value;
	var options={type:"POST", 
				url:"<%=request.getContextPath()%>/user/getAccInfoByDepId?depId="+obj.value, 
				dataType:"text", success: accDealer};
	$.ajax(options);
}

function accDealer(data,status){
	var accObj;
	eval("accObj =("+data+")");
	if(accObj.account!="null"){
		checkFlag = true;
		needAccCheck = false; //已经注册的帐号，不需再用AJAX确认
		account.value = accObj.account;
		account.readOnly = "readOnly";
		var obj = document.getElementById("acr");
		obj.innerHTML='<font color="#FF9966">账号已注册，只能修改帐号信息</font>';
		
		accObj.userName == 'null' || accObj.userName == undefined ? userName.value = "" : userName.value = accObj.userName;
		accObj.userPwd == 'null' || accObj.userPwd == undefined ? userPwd.value = "" : userPwd.value = accObj.userPwd;
		accObj.contacter == 'null' || accObj.contacter == undefined ? contacter.value = "" : contacter.value = accObj.contacter;
		accObj.phone == 'null' || accObj.phone == undefined ? phone.value = "" : phone.value = accObj.phone;
		accObj.email == 'null' || accObj.email == undefined ? email.value = "" : email.value = accObj.email;

		
	}else{
		needAccCheck = true;
		
		account.readOnly = "";
		account.value = "";
		userName.value = "";
		userPwd.value = "";
		contacter.value = "";
		phone.value = "";
		email.value = "";

		var obj = document.getElementById("acr");
		obj.innerHTML='<font color="#FF9966">此部门还未注册帐号</font>';
	}
}

function check(formData, jqForm, options) {

	if (f.account.value == ""){
		alert("必须填写帐号");
		return false;
	}
	if (f.orgName.valie == ""){
		alert("必须选择所属部门");
		return false;
	}
	if (f.userPwd.value == ""){
		alert("必须填写密码");
		f.userPwd.focus();
		return false;
	}
	if(!checkFlag){
		alert("您填写的帐号名已经被使用，请更换一个");
		return false;
	}
	return true;
}

function localResultResponse(data,status) {
	alert(data.msg)
	var obj = document.getElementById("acr");
	obj.innerHTML='';
}

function resetFun(){
	account.readOnly = "";
	account.value = "";
	userName.value = "";
	userPwd.value = "";
	contacter.value = "";
	phone.value = "";
	email.value = "";
	depId.value = "";
	account.readonly = false;
	var obj = document.getElementById("acr");
	obj.innerHTML='';
	//修改部门默认值为-1
	var obj = document.getElementById("orgName");  
	obj.selectedIndex = -1;
	
}
</script>
</head>
<body>
<form id="form1" name="form1" action="<%=request.getContextPath()%>/user/regByJxw" onsubmit="return false;">

<table class="top">
  <tr>
    <td width="40" class="topl"></td>
    <td width="840"><div class="plat_title"><img src="<%=request.getContextPath()%>/images/toptitle.gif" /></div></td>
    <td width="21"><a href="#" class="top_drop_btn"></a></td>
    <td width="20"><a href="#" class="maxbtn"></a></td>
    <td width="29"><a href="#" class="closebtn"></a></td>
  </tr>
</table>
<table class="content">
  <tr>
    <td class="main_l"></td>
    <td class="main_lbar"></td>
    <td width="918" valign="top">
	<div class="banner"><img src="<%=request.getContextPath()%>/images/banner.jpg" /></div>
	<div class="op_con">
    <table class="regtable">
  <tr>
<th colspan="2">经信委用户管理</th>
  </tr>
  <tr>
  <td colspan="2"></td>
  </tr>
  <tr>
    <td class="w02">帐号</td>
    <td><input type="text" class="intt"  name="account" id="account" onblur="checkAccount(this)"/><b>*</b><span id="acr"></span></td>
  </tr>
  
  <tr>
    <td class="w02">名称</td>
    <td><input type="text" class="intt" name="userName" id="userName"/><b>*</b></td>
  </tr>
  
  <tr>
    <td class="w02">密码</td>
    <td><input type="text" class="intt" name="userPwd" id="userPwd"/><b>*</b></td>
  </tr>
  
  <tr>
    <td class="w02">所属部门</td>
    <td><select class="intt" name="orgName" id="orgName" onchange="getAccByDep(this)">
		<c:forEach items="${depLis}" var="dep">
			<option value="${dep.depId}" >${dep.departmentName}</option>
		</c:forEach>
    </select><b>&nbsp;*</b></td>
  </tr>
  
<script>
	//修改部门默认值为-1
	var obj = document.getElementById("orgName");  
	obj.selectedIndex = -1;
</script>

  <tr>
    <td class="w02">所属部门编码</td>
    <td><input type="text" class="intt" name="depId" maxlength="11" id="depId" readonly="readonly"/><span>系统自动产生</span></td>
  </tr>
 
  <tr>
    <td class="w02">联系人</td>
    <td><input type="text" class="intt" name="contacter" id="contacter" maxlength="50"/></td>
  </tr>
  
  <tr>
    <td class="w02">联系电话</td>
    <td><input type="text" class="intt" name="phone" id="phone" maxlength="50"/></td>
  </tr>
  
  <tr>
    <td class="w02">电子邮件</td>
    <td><input type="text" class="intt" name="email" id="email" maxlength="50"/><span>找回密码必填</span></td>
  </tr>
  
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" value="提交" class="btn40" id="regBn"/>
		<input type="button" value="重置" class="btn40" id="resetBn" onclick="resetFun()"/>
    </td>
  </tr>
    <tr>
  <td colspan="2"></td>
  </tr>
</table>

	</div>
	</td>
    <td class="main_rbar"></td>
	<td class="main_r"></td>
  </tr>
</table>
</form>

<script>
//取页面元素代码，用于AJAX
account = document.getElementById("account");
userName = document.getElementById("userName");
userPwd = document.getElementById("userPwd");
orgName = document.getElementById("orgName");
contacter = document.getElementById("contacter");
phone = document.getElementById("phone");
email = document.getElementById("email");
depId = document.getElementById("depId");

window.onload=function (){
	f = document.getElementById("form1");

	var options={type:"POST", dataType:"json", beforeSubmit:check, success:localResultResponse};
	$('#form1').ajaxForm(options);
}
</script>
<table class="bot">
	<tr>
		<td width="41"><div class="botl"></div></td>
		<td width="867"></td>
		<td width="42"><div class="exit"></div></td>
	</tr>
</table>
<c:import url="/foot.jsp" />
</body>
</html>
